package br.com.fogas.impressora;

import br.com.fogas.database.entidade.NotaFiscal;
import br.com.fogas.impressora.ImpressoraBluetoothHelper.ImpressoraBluetoothListener;
import br.com.fogas.impressora.business.Imprimir_1_2_ViaNota_Boleto;
import br.com.fogas.modelo.Configuracao;
import br.com.fogas.utils.dialog.ProgressDialogBuilder;
import br.com.fogas.utils.task.ServiceTask;
import br.com.fogas.utils.task.ServiceTaskBusiness;
import android.content.Intent;
import android.support.v4.app.Fragment;

public class ImpressaoNotaEngine {

	private Fragment fragment;
	private ImpressoraBluetoothHelper impressoraBluetoothHelper;
	private ServiceTask serviceTask;
	private ServiceTaskBusiness impressaoTask;

	public ImpressaoNotaEngine(Fragment fragment) throws ImpressoraMPTException {
		this.fragment = fragment;
		this.impressoraBluetoothHelper = new ImpressoraBluetoothHelper(fragment, bluetoothListener);
	}
	
	public boolean isActivityForResult(int requestCode, int resultCode, Intent data) {
		return impressoraBluetoothHelper.isActivityForResult(requestCode, resultCode, data);
	}
	
	private ImpressoraBluetoothListener bluetoothListener = new ImpressoraBluetoothListener() {
		
		@Override
		public void impressoraPareada(boolean pareada) {
			if(pareada) {
				ProgressDialogBuilder progress = new ProgressDialogBuilder(fragment.getActivity())
				.setTitle("Title")
				.setMessage("Message");
				serviceTask = new ServiceTask(progress, impressaoTask);
				serviceTask.execute();
			}
		}
	};
	
	public void imprimir_1_2_ViaNota_Boleto(NotaFiscal notaFiscal, Configuracao configuracao) {
		this.impressaoTask = new Imprimir_1_2_ViaNota_Boleto(fragment, notaFiscal, configuracao);
		this.impressoraBluetoothHelper.checarImpressoraBluetooth();
	}
}